package com.viser.partyinrs.adapters;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;

import com.viser.partyinrs.entities.Mesto;
import com.viser.partyinrs.http.HttpDispatcher;

public class MestaAdapter extends DataAdapter {
	
	public MestaAdapter() {
		dispatcher = new HttpDispatcher();
	}
	
	@SuppressWarnings("finally")
	public ArrayList<Mesto> getMestoEntities(String upit) {
		ArrayList<Mesto> mesta = new ArrayList<Mesto>();
		
		try
		{
			String httpResponse = dispatcher.getHttpResponse_GET(pageBase+"pretraga_mesta_kjucna_rec.php?kljucna_rec="+upit);
			JSONArray mestoArray = new JSONArray(httpResponse);
			for(int i=0; i<mestoArray.length(); i++)
			{
				JSONObject mesto = mestoArray.getJSONObject(i);
				Mesto m = new Mesto();
				m.idMesto = mesto.getInt("id_mesto");
				m.idGrad = mesto.getInt("id_grad");
				m.naziv = mesto.getString("naziv");
				m.adresa = mesto.getString("adresa");
				m.sajt = mesto.getString("sajt");
				m.email = mesto.getString("email");
				m.telefon = mesto.getString("telefon");
				m.geoX = (float)mesto.getDouble("geo_x");
				m.geoY = (float)mesto.getDouble("geo_y");
				m.urlLogo = mesto.getString("url_logo");
				m.menadzer = mesto.getString("menadzer");
				m.muzika = mesto.getString("muzika");
				m.radi_od=mesto.getString("radi_od");
				m.radi_do=mesto.getString("radi_do");
				mesta.add(m);
			}
		}
		catch (Exception ex) { }
		finally {
			return mesta;
		}
	}
	
}
